package org.springblade.tms.module.demandorder.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.tms.module.demandextrainfo.base.DemandExtraService;
import org.springblade.tms.module.demandextrainfo.entity.TmDemandExtraInfo;
import org.springblade.tms.module.demandextrainfo.service.ITmDemandExtraInfoService;
import org.springblade.tms.module.demandextrainfo.vo.TmDemandExtraInfoVO;
import org.springblade.tms.module.demandextrainfo.wrapper.TmDemandExtraInfoWrapper;
import org.springblade.tms.module.demandorder.vo.TMDemandEventVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author: wzq
 * @className: DemandOpController
 * @createDate: 2022/3/9
 * @description: 需求单补全信息相关接口
 */
@RestController
@AllArgsConstructor
@Validated
@RequestMapping("demand/extra")
@Api(value = "需求单补全信息相关接口", tags = "需求单接口-wzq")
public class DemandOpController extends BladeController {

	private DemandExtraService demandExtraService;

	private ITmDemandExtraInfoService tmDemandExtraInfoService;

	//	/**
	//	 * 补全推送
	//	 */
	//	@GetMapping("send")
	//	@ApiOperationSupport(order = 1)
	//	@ApiOperation(value = "补全推送", notes = "传入需求单demandId")
	//	public R<String> send(@NotBlank Long demandId) {
	//		demandExtraService.fillDemandExtra(demandId);
	//		return R.data("推送成功");
	//	}

	/**
	 * 补全信息查看
	 */
	@GetMapping("view")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "补全信息详情", notes = "传入需求单demandId")
	public R<TmDemandExtraInfo> detail(@NotNull Long demandId) {
		TmDemandExtraInfo result = tmDemandExtraInfoService.getOne(TmDemandExtraInfo.buildWrapper(1, TmDemandExtraInfo.builder().parentId(demandId).build()));
		TmDemandExtraInfoVO tmDemandExtraInfoVO = TmDemandExtraInfoWrapper.build().entityVO(result);
		if (tmDemandExtraInfoVO == null) {
			R<TmDemandExtraInfo> objectR = new R<>();
			objectR.setCode(200);
			objectR.setSuccess(true);
			objectR.setData(TmDemandExtraInfo.builder().build());
			return objectR;
		}
		return R.data(tmDemandExtraInfoVO);
	}


	/**
	 * 补全信息
	 */
	@PostMapping("fill")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "补全信息", notes = "id不用传")
	public R<Long> fill(@RequestBody @Validated(TmDemandExtraInfo.FILL_INFO.class) TmDemandExtraInfoVO input) {
		return R.data(demandExtraService.fillDemandExtra(input));
	}


	/**
	 * 需求单事件变更
	 */
	@PostMapping("event")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "需求单事件变更")
	public R event(@RequestBody @Validated TMDemandEventVO input) {
		demandExtraService.eventChange(input);
		return R.success("成功");
	}

	/**
	 * 关闭需求单(点击运达)
	 */
	@PostMapping("close")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "关闭需求单(点击运达)", notes = "传入需求单demandId")
	public R<String> close(@NotNull Long demandId) {
		demandExtraService.closeDemand(demandId);
		return R.data("成功");
	}


}
